package modelLag;
import java.util.ArrayList;


/**
 * Description of the class ProductCon.
 * 
 * @author (Christian, Simon, Christoffer,Patrick, Umut)
 * @project (Semesterprojekt)
 * @version (2014.12.09)
 */
public class ProductCon
{
    
    private static ProductCon instance = null;
    private ArrayList<Product> products;

    /**
     * Constructor for objects of class ProductCon
     */
    private ProductCon(){
        products = new ArrayList<Product>();
        
        //test
        Product product1 = new Product(1, "Spartelmasse", "En masse med spartel", 9999.95, 1, 17);
        Product product2 = new Product(2, "MasseSpartel", "En spartel med masser af masse", 10, 2, 30);
        
        products.add(product1);
        products.add(product2);

    }

    /**
     * Returns an instance of ProductCon
     * 
     * @return an instance of ProductCon
     */ 
    public static ProductCon getInstance(){
      if(instance == null){
        instance = new ProductCon();    
      }
      return instance;
    }
    
    /**
     * Returns an object of the type Product.
     * 
     * @param ID is the user input for the ID of a Product.
     */
    public Product findProduct(int ID){
      int i = 0;
      boolean found = false;
      Product returnProduct = null;
      while (!found && i<products.size()+1){
          Product p = products.get(i);
        if (ID == p.getID()){
          found = true;
          returnProduct = p;
        }
        i++;
      }
      return returnProduct;
    }
    
}
